<?php
/**
 * Contains {@link Domain51_Auth_Adapter_Gmail}
 *
 * @package     Domain51
 * @subpackage  Domain51_Auth
 */

/**
 * Required library
 */
Solar::loadClass('Domain51_Auth_Adapter_Curl');

/**
 * A basic class to handle user authentication via a Gmail email account.
 *
 * This class attempts to grab a Gmail Atom feed for a user based on their
 * supplied username and password.  If the attempt was successful (i.e., 
 * Google returns a 200 HTTP response), we log them in.
 *
 * Note: The majority of the work done in this class is handled by its parent,
 * {@link Domain51_Auth_Adapter_Curl}.
 *
 * @package     Domain51
 * @subpackage  Domain51_Auth
 * @license     Release under the same license as Solar
 */
class Domain51_Auth_Adapter_Gmail extends Domain51_Auth_Adapter_Curl
{
    /**
     * Setup Gmail-specific configuraiton values for Curl adapter
     *
     * @inheritdoc
     */
    protected $_Domain51_Auth_Adapter_Gmail = array(
        'url' => 'https://mail.google.com/gmail/feed/atom',
        'curl_options' => array(
            CURLOPT_RETURNTRANSFER => 1,
            CURLOPT_FOLLOWLOCATION => 1
        )
    );
    
    
    /**
     * Filters return so Gmail email address is returned as "email [at] gmail [dot] com"
     *
     * @return string
     */
    public function getHandle() {
        $returnString = str_replace(
            array('@', 'gmail.com'),
            array(' [at] ', 'gmail [dot] com'),
            $this->_handle
        );
        
        return $returnString;
    }
}

?>
